import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/color.dart';
import 'package:material_collection_app/widget/common/underline_indicator.dart';

class TabbarScroll extends StatelessWidget {
  final List tabs;
  final EdgeInsets indicatorInsets;
  final TabController tabController;

  TabbarScroll({
    Key key,
    @required this.tabs,
    this.indicatorInsets = const EdgeInsets.fromLTRB(25, 0, 25, 3),
    this.tabController
  })
  : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return Theme(
      data: ThemeData(
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        primarySwatch: createMaterialColor(Color(0xFFeeeeee)),
        primaryColor: Colors.blue,
      ),
      child: Stack(
        children: <Widget>[
          Align(
            alignment: Alignment.centerLeft,
            child: InkWell(
              onTap: () {
                Navigator.pop(context);
              },
              child: Padding(
                padding: EdgeInsets.fromLTRB(25.w, 35.w, 25.w, 35.w),
                child: Image.asset('assets/arrow_return.png', width: 17.w,)
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerRight,
            child: Container(
              width: 670.w,
              child: TabBar(
                controller: tabController,
                indicator: UnderlineIndicator(
                  insets: indicatorInsets,
                ),
                labelPadding: EdgeInsets.symmetric(horizontal: 20.w), // label内边距
                isScrollable: true,
                indicatorSize: TabBarIndicatorSize.label,
                unselectedLabelColor: Colors.white,
                labelStyle: TextStyle( //选中文字样式
                  fontSize: 36.w, 
                  fontWeight: FontWeight.bold
                ), 
                unselectedLabelStyle: TextStyle( //未选中文字样式
                  fontSize: 14, fontWeight: FontWeight.w500
                ),
                tabs: tabs.map((item) => Tab(text: item['title'])).toList(),
              )
            )
          )
        ]
      )
    );
  }
}